/**
 * (C) Copyright 2009, 2015 Pharmacodia Technology Co.,Ltd.
 */

package cn.qn.controller.upload;

import cn.qn.dto.ResponseDTO;
import cn.qn.service.image.ImageService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Project ID：600YF17065
 * Resume：<br/>
 *
 * @author nishli
 * @version 
 * @see
 * @since 2017年2月22日
 */
@Controller
@RequestMapping(value="oss")
public class OSSController {

	@Reference(check = false)
	private ImageService imageApi;

	@RequestMapping(value="/getOSSProperties")
	@ResponseBody
	public ResponseDTO getOSSProperties(String filePath){
		if(StringUtils.isBlank(filePath)){
			filePath = "default";
		}
		return ResponseDTO.success(imageApi.getOSSProperties(filePath));
	}
	
	@RequestMapping(value="/getOSSPrivatePolicy", method=RequestMethod.POST)
	@ResponseBody
	public ResponseDTO getOSSPrivatePolicy(String filePath){
		return ResponseDTO.success(imageApi.generatePrivatePolicy(filePath));
	}
	
	@RequestMapping(value="/getPresignedUrl", method=RequestMethod.POST)
	@ResponseBody
	public ResponseDTO generatePresignedUrl(String key){
		return ResponseDTO.success(imageApi.generatePresignedUrl(key));
	}
	
	@RequestMapping(value="/deleteObject" ,method=RequestMethod.POST)
	@ResponseBody
	public void deleteObject(String objectKey){
		imageApi.deleteObject(objectKey);
	}

}
